package test;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Scanner;

public class Demo {
	public static void main(String[] args) {
		DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
		System.out.println("请输入日期：（年月日，格式：2008-1-1）：");
		Scanner dateInput = new Scanner(System.in);
		String str = dateInput.nextLine();
		try {
			Date date = format.parse(str);
			Calendar calendar = new GregorianCalendar();
			calendar.setTime(date);
			
			int thisDay = calendar.get(Calendar.DATE);
			
			calendar.set(Calendar.DATE, 1);
			
			int thisWeek = calendar.get(Calendar.DAY_OF_WEEK);	//获取当月一号为星期几
			int maxDate = calendar.getActualMaximum(Calendar.DATE);	//获取当月最大值
			
			String[] weekList = {"日","一","二","三","四","五","六"};
			for(String item : weekList){
				System.out.print(item+"\t");
			}
			System.out.println();
			for(int i=1;i<thisWeek;i++){
				System.out.print("\t");
			}
			for(int i=1;i<=maxDate;i++){
				if(i == thisDay){
					System.out.print("*");
				}
				System.out.print(i+"\t");			
				if(calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY){
					System.out.println();
				}
				calendar.add(Calendar.DATE, 1);
			}
		} catch (ParseException e) {
			e.printStackTrace();
		}
	}
}